<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>查看方案</title>
    <link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">
    <script type="text/javascript" src="../../res/js/Tools.js"></script>
    <script src="../../res/js/jquery-3.4.1.min.js" type="text/javascript"
            charset="utf-8"></script>
    <script src="../../js/login_common.js" charset="utf-8"></script>
    <script src="../../res/layui/layui.js" charset="utf-8"></script>
    <style>
        body{
            padding: 10px 20px 10px 10px;
        }
        .title_font{
            font-weight: bold;
        }
        #isRead,#notRead{
            border-radius: 10%;
        }

    </style>
</head>
<body>
<!--
<button class="layui-btn layui-icon layui-icon-file" id="export" lay-event="export"  data-type="reload">导出Word</button>
-->

<table class="layui-table " lay-even="" lay-skin="nob">
    <colgroup>
        <col width="100">
        <col width="150">
    </colgroup>
    <thead>
    <tr>
        <td class="title_font">方案名称</td>
        <td id="schemeName" style="width: 300px"></td>
        <td class="title_font">方案类型</td>
        <td id="schemeType"></td>
    </tr>
    </thead>
    <tbody>

    <tr>
        <td class="title_font">教练员</td>
        <td id="coachName"></td>
        <td class="title_font">创建时间</td>
        <td id="creatTime"></td>
    </tr>
    <tr>
        <td class="title_font">运动员</td>
        <td id="athleteName"></td>
        <td class="title_font">创建人</td>
        <td id="creater"></td>
    </tr>

    <tr>
        <td class="title_font">实施情况</td>
        <td id="resultExp" colspan="3"></td>
    </tr>
    <tr>
        <td class="title_font">实施效果</td>
        <td id="resultEffect" colspan="3"></td>
    </tr>
    <tr>
        <td class="title_font">反馈时间</td>
        <td id="resultTime"></td>
        <td class="title_font">审核状态</td>
        <td id="auditState"></td>
    </tr>
    <tr>
        <td class="title_font">申请理由</td>
        <td id="applyForExp" colspan="3"></td>

    </tr>
    <tr>
        <td class="title_font">审核人</td>
        <td id="auditCreater" colspan="3"></td>

    </tr>
    <tr>
        <td class="title_font">审核意见</td>
        <td id="auditExp"  colspan="3"></td>
    </tr>
    <tr>
        <td style="width: 100px" class="title_font">专家</td>
        <td id="expertName" colspan="3"></td>
    </tr>
    <tr>
        <td style="width: 100px" class="title_font">专家咨询结果</td>
        <td id="results" colspan="3"></td>
    </tr>
    <tr id="afterAdd">
        <td style="width: 100px" class="title_font" colspan="4">运动员建议：</td>
    </tr>



    <tr>
        <td class="title_font">附件一</td>
        <td id="file1"></td>
        <td class="title_font">附件二</td>
        <td id="file2"></td>
    </tr>
    <tr>
    </tr>
    <tr>
        <td class="title_font">附件三</td>
        <td id="file3"></td>
        <td class="title_font">实施附件</td>
        <td id="resultFile"></td>
    </tr>


    </tbody>
</table>
<form class="layui-form" id="commentForm">
    <input type="hidden" id="schemeId"/>
    <div class='layui-form-item layui-form-text'>
        <label class='layui-form-label'>建议</label>
        <div class='layui-input-block'>
            <textarea placeholder='请输入您的意见和建议' id='exp' name='exp' lay-verify='exp' class='layui-textarea'></textarea>
        </div>
    </div>
    <div class='layui-form-item'>
        <div class='layui-input-block'>
            <input type='button' class='layui-btn' lay-submit='' id="button" lay-filter='demo1' value="立即提交"/>
        </div>
    </div>

</form>
<script>
    //取上个页面传过来的方案id
    var schemeId=getQueryString("id");
    //点击文件导出
    $("#export").on("click",function(){
        var url="../../ExportServlet?action=scheme&id="+schemeId;
        location.href=url;
    });



    layui.use(['form', 'layedit', 'laydate','tree','element','upload'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , element = layui.element
            , upload = layui.upload;



        //自定义验证规则
        form.verify({
            exp: function (value) {
                if (!value.length) {
                    return '意见框不能包含空格';
                }else if(loginObj.user.companyNum!=="4"){
                    console.info(loginObj.manager.companyNum);
                    return '您不是运动员，不能提意见哦！';
                }
            }
        });

        //监听提交
        form.on('submit(demo1)', function (data) {
            $("#button").attr("disabled","disabled");
            var url2 = "../../../mentalTrainingController/addExp";
            var data2 = {schemeId: schemeId, exp:$("#exp").val()};
            $.ajax({
                url: url2,
                type: "post",
                data: data2,
                dataType: "json",
                success: function (obj) {
                    if(obj.num==1){
                        layer.msg(obj.msg, {
                            icon: 1,
                            time: 1000,
                        }, function () {
                            parent.table2.reload();//刷新父页面的表格数据
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                    }else{
                        layer.msg(obj.msg, {
                            icon: 2,
                            time: 1000,
                        }, function () {
                            parent.table2.reload();//刷新父页面的表格数据
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                    }
                }, error: function (e) {
                    alert('失败了');
                }

            });
        });
    });


    //根据id查询方案信息
    var url = "../../../mentalTrainingController/findResults";
    var data = {schemeId: schemeId};
    $.post(url, data, function (obj) {
        console.info(obj);
        $("#schemeId").val(obj.schemeId);
        $("#schemeName").text(obj.schemeName);
        if(obj.schemeType==1){
            $("#schemeType").text("运动康复方案");
        }else if(obj.schemeType==2){
            $("#schemeType").text("运动营养方案");
        }else if(obj.schemeType==3){
            $("#schemeType").text("心理训练方案");
        }
        $("#results").text(obj.results);
        $("#creatTime").text(getMyDate(obj.creatTime));
        $("#coachName").text(obj.coachName);

        //查询专家咨询结果
        var url2 = "../../../mentalTrainingController/selectAuExp";
        var data2 = {schemeId: schemeId};
        var state="";
        $.post(url2, data2, function (obj2) {
            $("#applyForExp").text(obj2.applyForExp);
            $("#results").text(obj2.results);
            $("#expertName").text(obj2.expertName);

        });

        //查询审核
        var url3 = "../../../mentalTrainingController/selectBySaId ";
        var data3 = {saId: schemeId};
        $.post(url3, data3, function (obj3) {
            if(obj3.auditState==="10"){
                $("#auditState").text("已申请");
            }else if(obj3.auditState==="20"){
                $("#auditState").text("已同意");
            }else if(obj3.auditState==="21"){
                $("#auditState").text("未同意");
            }else if(obj3.auditState==="30"){
                $("#auditState").text("待回复");
            }else if(obj3.auditState==="40"){
                $("#auditState").text("已回复");
            }
            $("#auditCreater").text(obj3.creater);
            $("#auditExp").text(obj3.auExp);

        },"json");



        //查询运动员
        var url1 = "../../../mentalTrainingController/selectAthleteById";
        var data1 = {schemeId: schemeId};
        $.post(url1, data1, function (obj1) {
            var str="";
            $.each(obj1,function (index,item) {
                console.info(item);
                if(item.athleteName){
                    if(item.isRead=="1"){
                        str+="<a class='layui-bg-blue' id='notRead'>"+item.athleteName+"</a>&nbsp;";
                    }
                    if(item.isRead=="0"){
                        str+="<a class='layui-bg-red' id='isRead'>"+item.athleteName+"</a>&nbsp;";
                    }
                }

                if(item.exp){

                    $("#afterAdd").after('<tr id="afterAdd">' +
                        '<td style="width: 100px" class="title_font">'+item.athleteName+'</td>' +
                        '<td colspan="3">'+item.exp+'</td>' +
                        '</tr>')
                }

            });
            $("#athleteName").append(str);
        });
        $("#creater").text(obj.creater);
        $("#resultExp").text(obj.resultExp);
        $("#resultEffect").text(obj.resultEffect);
        $("#resultTime").text(obj.resultTime);
        if(obj.file1){
            $("#file1").append('<a class="layui-btn layui-bg-blue layui-btn-xs  layui-icon layui-icon-download-circle" target="_blank" href="/hbats'+obj.file1+'">下载</a>');
        }
        if(obj.file2){
            $("#file2").append('<a class="layui-btn layui-bg-blue layui-btn-xs  layui-icon layui-icon-download-circle" target="_blank" href="/hbats'+obj.file2+'">下载</a>');
        }
        if(obj.file3){
            $("#file3").append('<a class="layui-btn layui-bg-blue layui-btn-xs  layui-icon layui-icon-download-circle" target="_blank" href="/hbats'+obj.file3+'">下载</a>');
        }
        if(obj.resultFile){
            $("#resultFile").append('<a class="layui-btn layui-bg-blue layui-btn-xs  layui-icon layui-icon-download-circle" target="_blank" href="/hbats'+obj.resultFile+'">下载</a>');
        }
        $("#remark").text(obj.remark);



    }, "json");








    /**
     *时间转换格式
     * @param str
     * @returns
     */
    function getMyDate(str){
        var oDate = new Date(str),
            oYear = oDate.getFullYear(),
            oMonth = oDate.getMonth()+1,
            oDay = oDate.getDate(),
            oTime = oYear +"-"+ getzf(oMonth) +"-"+ getzf(oDay);//最后拼接时间
        return oTime;
    };

    //补0操作
    function getzf(num){
        if(parseInt(num) < 10){
            num = '0'+num;
        }
        return num;
    }

</script>
</body>
</html>